package com.jacky.dropdownmenu;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.Toast;

import com.jacky.dropdownmenu.model.DropdownChild;
import com.jacky.dropdownmenu.model.DropdownGroup;
import com.jacky.dropdownmenu.view.DropdownButton;
import com.jacky.dropdownmenu.view.DropdownDoubleMenu;
import com.jacky.dropdownmenu.view.DropdownSingleMenu;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {

    DropdownSingleMenu menu;
    DropdownSingleMenu menu1;

    DropdownDoubleMenu menu2;


    ListView list;

    View mask;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        menu = (DropdownSingleMenu) this.findViewById(R.id.menu);


        DropdownGroup group = new DropdownGroup();
        group.setTitle("测试1");
        DropdownGroup group1 = new DropdownGroup();
        group1.setTitle("测试2");

        final List<DropdownGroup> datas = new ArrayList<>();
        datas.add(group);
        datas.add(group1);

        list = (ListView) findViewById(R.id.list);
        mask = findViewById(R.id.mask);
        menu.setData(datas, list, mask);


        menu.setDropdownSelected(new DropdownSingleMenu.onDropdownSelected() {
            @Override
            public void onSelected(DropdownGroup group, int position) {

                Toast.makeText(MainActivity.this, "" + position, Toast.LENGTH_SHORT).show();

                Log.i("@@", "" + datas.get(0).isSelected());
                Log.i("@@", "" + datas.get(1).isSelected());
            }

            @Override
            public void onOpen() {
                menu1.getClear();
                menu2.getClear();
            }
        });
        test1();
    }

    private void test1() {
        menu1 = (DropdownSingleMenu) this.findViewById(R.id.menu1);


        DropdownGroup group = new DropdownGroup();
        group.setTitle("测试1");
        DropdownGroup group1 = new DropdownGroup();
        group1.setTitle("测试1");
        List<DropdownGroup> datas = new ArrayList<>();
        datas.add(group);
        datas.add(group1);

        ListView list = (ListView) findViewById(R.id.list1);
        View mask = findViewById(R.id.mask1);

        menu1.setData(datas, list, mask);


        menu1.setDropdownSelected(new DropdownSingleMenu.onDropdownSelected() {
            @Override
            public void onSelected(DropdownGroup group, int position) {

                Toast.makeText(MainActivity.this, "" + position, Toast.LENGTH_SHORT).show();
            }

            @Override
            public void onOpen() {
                menu.getClear();
                menu2.getClear();
            }
        });
        test2();
    }

    private void test2() {


        List<DropdownGroup> group = new ArrayList<>();

        for (int i = 0; i < 10; i++) {

            List<DropdownChild> childs = new ArrayList<>();
            for (int j = 0; j < 10; j++) {
                DropdownChild child = new DropdownChild();
                child.setTitle(i + "光谷" + j + "号");
                childs.add(child);
            }
            DropdownGroup g = new DropdownGroup();
            g.setTitle("武汉" + i + "号");
            g.setChild(childs);
            group.add(g);
        }
        menu2 = (DropdownDoubleMenu) findViewById(R.id.menu2);

        LinearLayout ll = (LinearLayout) findViewById(R.id.ll);
        View mask = findViewById(R.id.mask2);
        menu2.setData(group, ll, mask);
        menu2.setDropdownSelected(new DropdownDoubleMenu.onDropdownSelected() {

            @Override
            public void onSelected(DropdownGroup group, int groupPosition, DropdownChild child, int childPosition) {
                Toast.makeText(MainActivity.this, "" + group.getTitle()+"==="+child.getTitle(), Toast.LENGTH_SHORT).show();
            }

            @Override
            public void onOpen() {
                menu.getClear();
                menu1.getClear();
            }
        });
    }
}
